<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/templates/HeaderTopMenuTemplate.xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:define name="conteudo">
        <p:panel id="pnlFiltro" header="Filtro">
            <h:panelGrid columns="2">
                <p:outputLabel for="txtFiltroNome" value="Título:" styleClass="negrito" />
                <p:inputText autocomplete="true" id="txtFiltroNome" size="30" maxlength="100" value="#{livroConsultaForm.filtroNome}" />
            </h:panelGrid>   
            <h:panelGrid columns="5">
                <p:commandButton id="btnPesquisar" 
                                 value="Pesquisar" 
                                 action="#{livroConsultaForm.onBotaoPesquisarClick}"
                                 ajax="true" update="dtlResultadoPesquisa"
                                 icon="ui-icon-search" />
                <p:commandButton id="btnCancelar" 
                                 value="Cancelar" 
                                 action="#{livroConsultaForm.onBotaoCancelarClick}"
                                 ajax="true" update="dtlResultadoPesquisa,txtFiltroNome" icon="ui-icon-cancel" />
            </h:panelGrid>
        </p:panel>
        <f:verbatim><br/></f:verbatim>
        <p:panel id="pnlResultadoPesquisa" header="Resultado Pesquisa">
            <p:dataTable id="dtlResultadoPesquisa" 
                         value="#{livroConsultaForm.resultadoPesquisa}"
                         var="livro">
                <p:column headerText="Título">
                    <h:outputText value="#{livro.titulo}"/>
                </p:column>
                <p:column headerText="ISBN">
                    <h:outputText value="#{livro.isbn}"/>
                </p:column>
                <p:column headerText="Tipo">
                    <h:outputText value="#{livro.tipo.descricao}"/>
                </p:column>    
                <p:column headerText="Publicado em">
                    <h:outputFormat value="{0, date, dd/MM/yyyy}">
                        <f:param value="#{livro.dataPublicacao.toGregorianCalendar().time}" />
                    </h:outputFormat>
                </p:column>
                <p:column headerText="Reserva" width="10%">
                    <p:commandLink  update=":form:rsvDetail" oncomplete="rsvDialog.show()">
                        <f:param name="idLivro" value="#{livro.id}" />
                        <p:graphicImage library="images" name="ico_lov.png"/>
                        <f:setPropertyActionListener value="#{livro}" target="#{livroConsultaForm.livro}" />
                    </p:commandLink>
                    &nbsp;
                    <h:commandLink action="/emprestimo/emprestimoCadastroForm.xhtml">
                        <p:graphicImage library="images" name="ico_plus.png"/>
                        <f:param name="idLivro" value="#{livro.id}" />
                    </h:commandLink>
                    &nbsp;
                    <h:commandLink action="/emprestimo/emprestimoExclusaoForm.xhtml">
                        <p:graphicImage library="images" name="ico_del.png"/>
                        <f:param name="idLivro" value="#{livro.id}" />
                    </h:commandLink>
                </p:column>

            </p:dataTable>
        </p:panel>
        
        <p:dialog header="Reservas" widgetVar="rsvDialog" modal="true" showEffect="blind" hideEffect="explode" resizable="false">
           <p:outputPanel id="rsvDetail" style="text-align:center;">
               
               <p:dataList value="#{livroConsultaForm.getHistoricoEmprestimos()}" var="emp" type="definition">
                   <f:facet name="header">
                       Histórico Reservas
                   </f:facet>
                   <p:outputLabel style="font-weight: bold" value="Dt. Reserva: " /> <h:outputText value="#{emp.dtEmprestimo.toGregorianCalendar().time}"><f:convertDateTime pattern="dd/MM/yyyy"></f:convertDateTime></h:outputText>
                   &nbsp;
                   <p:outputLabel style="font-weight: bold" value="Dt. Devolução: " /> <h:outputText value="#{emp.dtDevolucao.toGregorianCalendar().time}"><f:convertDateTime pattern="dd/MM/yyyy"></f:convertDateTime></h:outputText>
               </p:dataList>
               <p:dataList value="#{livroConsultaForm.getEmprestimosAtuais()}" var="emp" type="definition">
                   <f:facet name="header">
                       Reservas Agendadas
                   </f:facet>
                   <p:outputLabel style="font-weight: bold" value="Dt. Reserva: " /> <h:outputText value="#{emp.dtEmprestimo.toGregorianCalendar().time}"><f:convertDateTime pattern="dd/MM/yyyy"></f:convertDateTime></h:outputText>
                   &nbsp;
                   <p:outputLabel style="font-weight: bold" value="Dt. Devolução: " /> <h:outputText value="#{emp.dtDevolucao.toGregorianCalendar().time}"><f:convertDateTime pattern="dd/MM/yyyy"></f:convertDateTime></h:outputText>
               </p:dataList>
        </p:outputPanel>
    </p:dialog>
        
    </ui:define>

</ui:composition>
